직선으로 나누기 어려운 데이터를 분류하는 데 한계가 있는 선형 모델을 넘어설 차례입니다. 오늘은 파이토치 워크플로우를 활용해 딥 뉴럴 네트워크(DNN) 복잡한 비선형 결정 경계를 학습할 수 있는 복잡하고 비선형적인 결정 경계 현실 세계의 분류 작업에 필수적입니다.
1. 비선형 데이터 시각화의 필요성
첫 번째 단계는 두 달 Moon 분포와 같은 도전적인 합성 데이터셋을 만들어, 단순한 선형 모델이 왜 실패하는지 시각적으로 보여주는 것입니다. 이 설정은 클래스를 구분하는 복잡한 곡선을 근사하기 위해 깊은 아키텍처를 사용해야 함을 강요합니다.
데이터 속성
- 데이터 구조: 합성 데이터 특징 (예: 2개의 특징을 가진 1000개 샘플에 대한 $1000 \times 2$).
- 출력 유형: 단일 확률 값으로, 일반적으로
torch.float32클래스 소속을 나타냅니다. - 목표: 층별 계산을 통해 곡선 형태의 결정 경계 만들고자 합니다.
비선형 활성화의 힘
DNN의 핵심 원리는 레이어에서 비선형성을 함수를 통해 도입하는 것입니다. 예를 들어 ReLU와 같은 함수를 통해 가능합니다. 이러한 기능 없이 층을 쌓으면 깊이에 관계없이 단순히 하나의 큰 선형 모델이 되기 때문입니다.
TERMINALbash — classification-env
> Ready. Click "Run" to execute.
>
TENSOR INSPECTOR Live
Run code to inspect active tensors
Question 1
What is the primary purpose of the ReLU activation function in a hidden layer?
Question 2
Which activation function is required in the output layer for a binary classification task?
Question 3
Which loss function corresponds directly to a binary classification problem using a Sigmoid output?
Challenge: Designing the Core Architecture
Integrating architectural components for non-linear learning.
You must build a
nn.Module for the two-moons task. Input features: 2. Output classes: 1 (probability).
Step 1
Describe the flow of computation for a single hidden layer in this DNN.
Solution:
Input $\to$ Linear Layer (Weight Matrix) $\to$ ReLU Activation $\to$ Output to Next Layer.
Input $\to$ Linear Layer (Weight Matrix) $\to$ ReLU Activation $\to$ Output to Next Layer.
Step 2
What must the final layer size be if the input shape is $(N, 2)$ and we use BCE loss?
Solution:
The output layer must have size $(N, 1)$ to produce a single probability score per sample, matching the label shape.
The output layer must have size $(N, 1)$ to produce a single probability score per sample, matching the label shape.